package com.mattmckay.server;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Convert {

	public static byte[] FileToByteArray(String FileName) throws IOException
	{
		
		File imagefile = new File(FileName);
		FileInputStream fis = new FileInputStream(imagefile);
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		byte[] buf = new byte[1024];
		for(int readNum;(readNum=fis.read(buf))!=-1;){
			bos.write(buf, 0, readNum);
		}
		return bos.toByteArray();
	}
	
	public static byte[] InputStreamToByteArray(InputStream instream)throws IOException {
	ByteArrayOutputStream bos;
	bos = new ByteArrayOutputStream();
	byte[] buf = new byte[1024];
	int len;
	while((len =instream.read(buf, 0, 1024))!= -1)
	{
		bos.write(buf, 0, len);
	}
	return bos.toByteArray();
	}
}
